/**
 * 主要程序框架
 * <p>规定客户端样式、以及包含的内容<br>
 * <p>包含内容：选择读卡器类型选择器（包含：ACS ACR1251 1S READER PICC 0;ACS ACR1251 1S CL READER SAM 0;）<br>
 * <p>初始化按钮：initialize;监听函数：ButtonInitialize;<br>
 * <p>连接读卡器按钮：connect;监听函数：ButtonConnect;<br>
 * <p>获取数据按钮：getData;监听函数：ButtonGetData;<br>
 * <p>发送数据按钮：SendCardCommand;监听函数：ButtonSendCardCommand;<br>
 * @author 吴杨君
 * @author 孔令炜
 * @version 1.0*/
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JComboBox;
import javax.swing.JButton;
import javax.swing.border.TitledBorder;
import javax.swing.JCheckBox;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import java.awt.Toolkit;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.KeyAdapter;
import java.sql.*;
@SuppressWarnings({ "unused", "serial" })
public class FrameOtherPicc extends JFrame implements
		ReaderEvents.TransmitApduHandler, ActionListener, KeyListener {
	//实现监听器、键盘监听、鼠标监听
	private JPanel contentPane;
	private JTextField TextFieldCla;
	private JTextField TextFieldIns;
	private JTextField TextFieldP1;
	private JTextField TextFieldP2;
	private JTextField TextFieldLc;
	private JTextField TextFieldLe;
	private JButton ButtonInitialize;
	private JButton ButtonConnect;
	private JButton ButtonGetData;
	private JButton ButtonSendCardCommand;
	private JButton ButtonClear;
	private JButton ButtonReset;
	private JButton ButtonQuit;
	private JCheckBox CheckBoxIsoACard;
	private JTextArea TextAreaApduLogs;
	private JComboBox ComboBoxReaderNames;

	private PiccClass _piccClass;
	private PcscReader _pcscReader;
	private JTextArea TextAreaData;

	/**
	 * Launch the application.
	 * 线程：主框架线程
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					FrameOtherPicc frame = new FrameOtherPicc();//实现FrameOtherPicc()
					frame.setVisible(true);//窗体可视
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 * @param contentPane
	 * @serialData 2015/9/10
	 * setBounds(300, 100, 488, 620);坐标X:300px;y:100px;宽度：488px;高度：620px;
	 */
	public FrameOtherPicc() {
		
		setTitle("PC端");
		setFont(new Font("Microsoft YaHei", Font.PLAIN, 12));
		setResizable(true);//是否可以更改界面大小
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(300, 100, 488, 620);//界面参数
		contentPane = new JPanel();//面板
		contentPane.setFont(new Font("Microsoft YaHei", Font.PLAIN, 10));
		contentPane.setBorder(new EmptyBorder(20, 20, 20, 20));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		//添加标签
		JLabel lblSelectReader = new JLabel("选择读卡器类型");
		lblSelectReader.setFont(new Font("Microsoft YaHei", Font.PLAIN, 10));
		lblSelectReader.setBounds(35, 15, 100, 15);
		contentPane.add(lblSelectReader);
		//添加显示读卡器类型盒子
		ComboBoxReaderNames = new JComboBox();
		ComboBoxReaderNames.setFont(new Font("Microsoft YaHei", Font.PLAIN, 10));
		ComboBoxReaderNames.setBounds(125, 12, 225, 20);
		contentPane.add(ComboBoxReaderNames);
		//添加初始化按钮
		ButtonInitialize = new JButton("Initialize");
		ButtonInitialize.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				initialize();
			}
		});
		ButtonInitialize.setFont(new Font("Microsoft YaHei", Font.PLAIN, 10));
		ButtonInitialize.setBounds(35, 39, 155, 23);
		contentPane.add(ButtonInitialize);

		ButtonConnect = new JButton("Connect");
		ButtonConnect.setEnabled(false);
		ButtonConnect.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				connect();
			}
		});
		ButtonConnect.setFont(new Font("Verdana", Font.PLAIN, 10));
		ButtonConnect.setBounds(35, 65, 155, 23);
		contentPane.add(ButtonConnect);

		JPanel panel = new JPanel();
		panel.setFont(new Font("Microsoft YaHei", Font.PLAIN, 10));
		panel.setBorder(new TitledBorder(null, "Get Data验证数据",
				TitledBorder.LEFT, TitledBorder.TOP, null, null));
		panel.setBounds(35, 99, 323, 58);
		contentPane.add(panel);
		panel.setLayout(null);

		CheckBoxIsoACard = new JCheckBox("ISO 14443-A Card");
		CheckBoxIsoACard.setFont(new Font("Microsoft YaHei", Font.PLAIN, 10));
		CheckBoxIsoACard.setBounds(6, 20, 145, 23);
//		panel.add(CheckBoxIsoACard);

		ButtonGetData = new JButton("Get Data");
		ButtonGetData.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				getData();
			}
		});
		ButtonGetData.setFont(new Font("Verdana", Font.PLAIN, 10));
		ButtonGetData.setBounds(20, 20, 155, 23);
		panel.add(ButtonGetData);
        //发送数据
		JPanel panel_1 = new JPanel();
		panel_1.setFont(new Font("Verdana", Font.PLAIN, 10));
		panel_1.setBorder(new TitledBorder(null, "Send Data Command",
				TitledBorder.LEFT, TitledBorder.TOP, null, null));
		panel_1.setBounds(10, 168, 323, 213);
        //		contentPane.add(panel_1);
		panel_1.setLayout(null);

		ButtonSendCardCommand = new JButton("Send Card Command");
		ButtonSendCardCommand.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				sendCommandData();
			}
		});
		ButtonSendCardCommand.setBounds(158, 180, 155, 23);
		ButtonSendCardCommand.setFont(new Font("Verdana", Font.PLAIN, 10));
		panel_1.add(ButtonSendCardCommand);

		JLabel lblCla = new JLabel("CLA");
		lblCla.setFont(new Font("Verdana", Font.PLAIN, 10));
		lblCla.setBounds(20, 25, 29, 14);
		panel_1.add(lblCla);

		JLabel lblIns = new JLabel("INS");
		lblIns.setFont(new Font("Verdana", Font.PLAIN, 10));
		lblIns.setBounds(67, 25, 29, 14);
		panel_1.add(lblIns);

		JLabel lblP = new JLabel("P1");
		lblP.setFont(new Font("Verdana", Font.PLAIN, 10));
		lblP.setBounds(115, 25, 29, 14);
		panel_1.add(lblP);

		JLabel lblP_1 = new JLabel("P2");
		lblP_1.setFont(new Font("Verdana", Font.PLAIN, 10));
		lblP_1.setBounds(158, 25, 29, 14);
		panel_1.add(lblP_1);

		JLabel lblLc = new JLabel("Lc");
		lblLc.setFont(new Font("Verdana", Font.PLAIN, 10));
		lblLc.setBounds(199, 25, 29, 14);
		panel_1.add(lblLc);

		JLabel lblLe = new JLabel("Le");
		lblLe.setFont(new Font("Verdana", Font.PLAIN, 10));
		lblLe.setBounds(243, 25, 29, 14);
		panel_1.add(lblLe);

		TextFieldCla = new JTextField();
		TextFieldCla.setFont(new Font("Verdana", Font.PLAIN, 10));
		TextFieldCla.setBounds(15, 45, 37, 20);
		panel_1.add(TextFieldCla);

		TextFieldIns = new JTextField();
		TextFieldIns.setFont(new Font("Verdana", Font.PLAIN, 10));
		TextFieldIns.setColumns(2);
		TextFieldIns.setBounds(59, 45, 37, 20);
		panel_1.add(TextFieldIns);

		TextFieldP1 = new JTextField();
		TextFieldP1.setFont(new Font("Verdana", Font.PLAIN, 10));
		TextFieldP1.setColumns(2);
		TextFieldP1.setBounds(103, 45, 37, 20);
		panel_1.add(TextFieldP1);

		TextFieldP2 = new JTextField();
		TextFieldP2.setFont(new Font("Verdana", Font.PLAIN, 10));
		TextFieldP2.setColumns(2);
		TextFieldP2.setBounds(147, 45, 37, 20);
		panel_1.add(TextFieldP2);

		TextFieldLc = new JTextField();
		TextFieldLc.setFont(new Font("Verdana", Font.PLAIN, 10));
		TextFieldLc.setColumns(2);
		TextFieldLc.setBounds(191, 45, 37, 20);
		panel_1.add(TextFieldLc);

		TextFieldLe = new JTextField();
		TextFieldLe.setFont(new Font("Verdana", Font.PLAIN, 10));
		TextFieldLe.setColumns(2);
		TextFieldLe.setBounds(235, 45, 37, 20);
		panel_1.add(TextFieldLe);

		JLabel lblDataIn = new JLabel("Data In");
		lblDataIn.setFont(new Font("Verdana", Font.PLAIN, 10));
		lblDataIn.setBounds(15, 76, 59, 14);
		panel_1.add(lblDataIn);

		JScrollPane scrollPane_1 = new JScrollPane();
		scrollPane_1.setBounds(18, 100, 293, 68);
		panel_1.add(scrollPane_1);

		TextAreaData = new JTextArea();
		TextAreaData.setFont(new Font("Verdana", Font.PLAIN, 10));
		TextAreaData.setWrapStyleWord(true);
		TextAreaData.setLineWrap(true);
		scrollPane_1.setViewportView(TextAreaData);
        //信息打印
		JLabel lblApduLogs = new JLabel("APDU Logs");
		lblApduLogs.setFont(new Font("Microsoft YaHei", Font.PLAIN, 10));
		lblApduLogs.setBounds(35, 160, 168, 14);
		contentPane.add(lblApduLogs);

		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(35, 180, 400, 346);
		contentPane.add(scrollPane); 

		TextAreaApduLogs = new JTextArea();
		TextAreaApduLogs.setFont(new Font("Microsoft YaHei", Font.PLAIN, 10));
		TextAreaApduLogs.setEditable(false);
		TextAreaApduLogs.setWrapStyleWord(true);
		scrollPane.setViewportView(TextAreaApduLogs);

		ButtonClear = new JButton("Clear");
		ButtonClear.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				clear();
			}
		});
		ButtonClear.setFont(new Font("Microsoft YaHei", Font.PLAIN, 10));
		ButtonClear.setBounds(35, 535, 100, 23);
		contentPane.add(ButtonClear);

		ButtonReset = new JButton("Reset");
		ButtonReset.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				disconnect();
			}
		});
		ButtonReset.setFont(new Font("Microsoft YaHei", Font.PLAIN, 10));
		ButtonReset.setBounds(175, 535, 100, 23);
		contentPane.add(ButtonReset);

		ButtonQuit = new JButton("Quit");
		ButtonQuit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				quit();
			}
		});
		ButtonQuit.setFont(new Font("Microsoft YaHei", Font.PLAIN, 10));
		ButtonQuit.setBounds(305, 535, 100, 23);
		contentPane.add(ButtonQuit);

		TextFieldCla.addKeyListener(this);
		TextFieldIns.addKeyListener(this);
		TextFieldLc.addKeyListener(this);
		TextFieldLe.addKeyListener(this);
		TextFieldP1.addKeyListener(this);
		TextFieldP2.addKeyListener(this);

		_pcscReader = new PcscReader();

		// Instantiate an event handler object
		_pcscReader.setEventHandler(new ReaderEvents());

		// Register the event handler implementation of this class
		_pcscReader.getEventHandler().addEventListener(this);

		_piccClass = new PiccClass(_pcscReader);

		resetEnableControls(false);
		TextAreaApduLogs.setText("Program Ready\r\n");
	}

	private void resetEnableControls(boolean isEnabled) {
		// ButtonConnect.setEnabled(isDefault);
		ButtonGetData.setEnabled(isEnabled);
		ButtonSendCardCommand.setEnabled(isEnabled);
		CheckBoxIsoACard.setEnabled(isEnabled);

		TextFieldCla.setEnabled(isEnabled);
		TextFieldIns.setEnabled(isEnabled);
		TextFieldLc.setEnabled(isEnabled);
		TextFieldLe.setEnabled(isEnabled);
		TextFieldP1.setEnabled(isEnabled);
		TextFieldP2.setEnabled(isEnabled);
		TextAreaData.setEnabled(isEnabled);

		TextFieldCla.setText("");
		TextFieldIns.setText("");
		TextFieldLc.setText("");
		TextFieldLe.setText("");
		TextFieldP1.setText("");
		TextFieldP2.setText("");
		TextAreaData.setText("");

	}
/**
 * 初始化函数 initializ
 * @param readerList
 * @throws Exception ex
 * 方法：addMsgToLog()*/
	private void initialize() {
		String[] readerList = null;

		try {
			readerList = _pcscReader.listTerminals();
			if (readerList.length == 0) {
				JOptionPane.showMessageDialog(this, "No PC/SC reader detected");
				return;
			}

			ComboBoxReaderNames.removeAllItems();

			for (int i = 0; i < readerList.length; i++) {
				if (!readerList.equals(""))
					ComboBoxReaderNames.addItem(readerList[i]);
				else
					break;
			}

			ComboBoxReaderNames.setSelectedIndex(0);
			ButtonConnect.setEnabled(true);

			addMsgToLog("\r\nInitialize Success");
		} catch (Exception ex) {
			addMsgToLog(ex.getMessage());
		}

	}

	private void connect() {
		try {
			String readerName = (String) ComboBoxReaderNames.getSelectedItem();

			_pcscReader.connect(readerName, "*");

			addMsgToLog("Successfully connected to " + readerName);

			ButtonInitialize.setEnabled(false);
			ButtonConnect.setEnabled(false);
			resetEnableControls(true);
		} catch (Exception ex) {
			addMsgToLog(ex.getMessage());
		}

	}

	private void getData() {
		try {
			byte uIso14443A;
			byte[] uCardVersion;

			if (CheckBoxIsoACard.isSelected())
				uIso14443A = 0x01;
			else
				uIso14443A = 0x00;

			addTitleToLog("Get Data");
			uCardVersion = _piccClass.getData(uIso14443A);

			if (CheckBoxIsoACard.isSelected()) {
				addMsgToLog("\r\nUID: "
						+ Helper.byteAsString(uCardVersion, true));
			} else {
				if (Helper.byteAsString(uCardVersion, true).equals("23 1A 3F 65 ")) {					
					  String driver = "com.mysql.jdbc.Driver";         // 驱动程序名
			           String url = "jdbc:mysql://localhost/movie";     // URL指向要访问的数据库名         
			           String user = "root";       // MySQL配置时的用户名
			           String password = "";      // MySQL配置时的密码
			           try { 
			            Class.forName(driver);    // 加载驱动程序
			            Connection conn = DriverManager.getConnection(url, user, password);      // 连续数据库
			            if(!conn.isClosed()) 
			             System.out.println("Succeeded connecting to the Database!");     //验证是否连接成功
			            Statement statement = conn.createStatement();               // statement用来执行SQL语句
			            String sql = "select * from movies where name='lingwei,kong'";                  // 要执行的SQL语句
			            ResultSet rs = statement.executeQuery(sql);       // 结果集
			            System.out.println("---------------------------------------------------------" +
			            		"-----------------------------------------------------------------------" +
			            		"-------------------------------------------------------------------------");
			            System.out.println("执行结果如下所示:");
			            System.out.println("-------------------------------------------------------------------" +
			            		"------------------------------------------------------------------------------" +
			            		"--------------------------------------------------------------------------------");
			            System.out.println("\t" +" 电影名" + "\t\t" + "上映时间 " + "\t\t" + "导演"+"" +
			            		 "\t\t" +"主演"+ "\t\t" +"电影类型"+ "\t\t" +"国家"+ "\t\t" +"语种"+ "\t\t" +
			            		 "时长"+ "\t\t" +"观影者"+ "\t\t\t" +"开始时间"+ "\t\t\t" +"放映厅"+ "\t\t" +"座位号"+ "\t\t" +"票价");
			            System.out.println("-------------------------------------------------------------------------" +
			            		"------------------------------------------------------------------------------------" +
			            		"-----------------------------------------------------------------------------------");
			            String name = null;
			            while(rs.next()) {
			            	name = rs.getString("movieName");//选择电影名 
			                String time1 = rs.getString("time");//选择上映时间
			                String director = rs.getString("director");//选择导演
			                String actor = rs.getString("actor");//选择主演
			                String type1 = rs.getString("type");//选择电影类型
			                String country1 = rs.getString("country");//选择电影生产国
			                String language1 = rs.getString("language");//选择电影语种
			                String lasttime = rs.getString("lasttime");//选择电影时长
			                String name1 = rs.getString("name");//选择观影者姓名
			                String date1 = rs.getString("date");//选择观影时间
			                String room1 = rs.getString("room");//选择观影者房间
			                String seat = rs.getString("seat");//选择观影者房间
			                String price = rs.getString("price");//选择电影票价
			                System.out.println(name + "\t" +time1+director+"\t\t"+actor+"\t\t"+type1+"\t\t"+
			               		 country1+"\t\t"+language1+"\t\t"+
			               		 lasttime+"\t"+name1+"\t"+date1+"\t\t"+room1+"\t\t"+seat+"\t\t"+price);//输出结果
			                addMsgToLog("succeed!\n信息验证成功（已买票）\n"+"电影名："+name+"（碟中谍5）\n"+"上映时间："+time1+"\n"+"导演："+director+"\n"+"主演："+
			                		actor+"高总\n"+"电影类型："+type1+"\n"+"国家"+country1+"\n"+"语种"+language1+"\n"+
			                		"时长："+lasttime+"\n"+"观影者："+name1+"孔令炜\n"+"观看时间："+date1+"\n放映厅："+room1+"\n座位："+seat+"\n票价："+price+"元");
			            }
			            rs.close();
			            conn.close();
			           } catch(ClassNotFoundException e) {
			            System.out.println("Sorry,can`t find the Driver!"); 
			            e.printStackTrace();
			           } catch(SQLException e) {
			            e.printStackTrace();
			           } catch(Exception e) {
			            e.printStackTrace();
			           }
				} else {
					addMsgToLog("failed! you didn't buy the ticket（请买票）");
					addMsgToLog("\r\nATS: "	+ Helper.byteAsString(uCardVersion, true));
				}
			}
		} catch (Exception ex) {
			addMsgToLog(ex.getMessage());
		}
	}
/**
 * @param byte uCla, uIns, uP1, uP2;
 * @param byte uLc= 0x00;byte uLe = 0x00;
 * @param byte[] uData = null;
 * @param int iDataLen = 0;
 * @param int iCaseType = 0;*/
	private void sendCommandData() {
		byte uCla, uIns, uP1, uP2;
		byte uLc = 0x00;
		byte uLe = 0x00;
		byte[] uData = null;
		int iDataLen = 0;
		int iCaseType = 0;

		try {
			// Validate inputs
			if (TextFieldCla.getText().length() < 2) {
				TextFieldCla.requestFocus();
				return;
			}

			if (TextFieldIns.getText().length() < 2) {
				TextFieldIns.requestFocus();
				return;
			}

			if (TextFieldP1.getText().length() < 2) {
				TextFieldP1.requestFocus();
				return;
			}

			if (TextFieldP2.getText().length() < 2) {
				TextFieldP2.requestFocus();
				return;
			}

			uCla = (byte) ((Integer) Integer.parseInt(TextFieldCla.getText(),
					16)).byteValue();
			uIns = (byte) ((Integer) Integer.parseInt(TextFieldIns.getText(),
					16)).byteValue();
			uP1 = (byte) ((Integer) Integer.parseInt(TextFieldP1.getText(), 16))
					.byteValue();
			uP2 = (byte) ((Integer) Integer.parseInt(TextFieldP2.getText(), 16))
					.byteValue();

			if (TextFieldLc.getText().length() > 0
					&& TextFieldLc.getText() != "00") {
				if (TextAreaData.getText().length() == 0) {
					TextAreaData.requestFocus();
					return;
				}
			}

			if (TextFieldLc.getText().length() > 0) {
				uLc = (byte) ((Integer) Integer.parseInt(TextFieldLc.getText(),
						16)).byteValue();

				if (uLc > 0x00) {
					uData = Helper.getBytes(TextAreaData.getText(), " ");
					if (uData == null) {
						addMsgToLog("\r\nData In field has invalid format.");
						TextAreaData.requestFocus();
						return;
					}

					iDataLen = uData.length;

					if ((int) uLc != iDataLen) {
						addMsgToLog("\r\nLc does not match length of data.");
						TextFieldLc.requestFocus();
						return;
					}
				}
			}

			if (TextFieldLe.getText().length() > 0) {
				uLe = (byte) ((Integer) Integer.parseInt(TextFieldLe.getText(),
						16)).byteValue();
			}
//获取数据长度 TextFieldLc.getText().length()
			if (TextFieldLc.getText().length() == 0) {
				if (uLe == 0x00)
					iCaseType = 0;
				else
					iCaseType = 1;
			} else {
				if (uLe == 0x00)
					iCaseType = 2;
				else
					iCaseType = 3;
			}

			addTitleToLog("Send Command");
			//_piccClass.sendCommand方法
			_piccClass.sendCommand(iCaseType, uCla, uIns, uP1, uP2, uLc, uLe,
					uData);
		} catch (Exception ex) {
			addMsgToLog(ex.getMessage());
		}
	}
/**
 * 断开连接*/
	public void disconnect() {
		try {
			// disconnect
			if (_pcscReader.isConnectionActive())
				_pcscReader.disconnect();

			addMsgToLog("SCardDisconnect Success");
			TextAreaApduLogs.setText("Program Ready\r\n");
			resetEnableControls(false);
			CheckBoxIsoACard.setSelected(false);
			ComboBoxReaderNames.removeAllItems();
			ButtonInitialize.setEnabled(true);
		} catch (Exception ex) {
			addMsgToLog(ex.getMessage());
		}

	}
/**
 * 退出程序*/
	public void quit() {

		this.dispose();
	}
/**
 * 清除数据*/
	public void clear() {

		TextAreaApduLogs.setText("");
	}
/**
 * 添加数据头*/
	public void addMsgToLog(String prefixStr, byte[] buff, String postfixStr,
			int buffLen) {
		String tmpStr = "";

		if (buff.length < buffLen)
			return;

		tmpStr = null;

		// Convert each byte from buff to its string representation.
		for (int i = 0; i < buffLen; i++)
			tmpStr += String.format("{0:X2}", buff[i]) + " ";

		addMsgToLog(prefixStr + tmpStr + postfixStr);
	}

	void addTitleToLog(String title) {
		TextAreaApduLogs.setSelectedTextColor(Color.black);
		TextAreaApduLogs.append("\r\n" + title + "\r\n");
	}

	void addMsgToLog(String msg) {
		TextAreaApduLogs.append(msg + "\r\n");
	}
/**
 *onSendCommand发送数据 */
	public void onSendCommand(ReaderEvents.TransmitApduEventArg event) {
		addMsgToLog("<< " + event.getAsString(true));
	}
/**
*onSendCommand接受数据 */
	public void onReceiveCommand(ReaderEvents.TransmitApduEventArg event) {
		addMsgToLog(">> " + event.getAsString(true));
	}
/**
 * 电脑键盘监听*/
	@Override
	public void keyPressed(KeyEvent arg0) {
		// TODO Auto-generated method stub

	}
/**
	 * 电脑键盘监听*/
	@Override
	public void keyReleased(KeyEvent arg0) {
		// TODO Auto-generated method stub

	}
/**
	 * 电脑键盘监听*/
	public void keyTyped(KeyEvent ke) {
		Character x = (Character) ke.getKeyChar();
		char empty = '\r';

		// Check valid characters
		/*
		 * if(textFieldAmount.isFocusOwner()) { if (VALIDCHARS.indexOf(x) == -1
		 * ) ke.setKeyChar(empty); }
		 */

		// Limit character length

		if (((JTextField) ke.getSource()).getText().length() >= 2) {
			ke.setKeyChar(empty);
			return;
		}

	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub

	}
}